package com.weseal.controller;

import com.weseal.controller.base.BaseController;
import com.weseal.response.CommonResult;
import com.weseal.utils.CommonUtils;
import com.weseal.vo.BannerVo;
import com.weseal.vo.CategoryVo;
import com.weseal.vo.IndexVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author weixiaoqing
 * @description
 * @create 2017/9/7
 * @company 上海富捷信息技术有限公司
 */
@Controller
public class IndexController extends BaseController {
	
	
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult index() {
		CommonResult result = CommonResult.initSuccess();
		IndexVo indexVo = new IndexVo();
		List<BannerVo> bannerVoList = new ArrayList<>();
		for (int i =0; i< 4;i++) {
			BannerVo bannerVo = new BannerVo();
			bannerVo.setBusinessId(i+1L);
			bannerVo.setId(i+1L);
			bannerVo.setPicUrl("http://www.jiaonainai.cn/static/images/comment.png");
			bannerVoList.add(bannerVo);
		}
		
		List<CategoryVo> categoryVos = new ArrayList<>();
		
		for (int i =0; i< 10;i++) {
			CategoryVo categoryVo = new CategoryVo();
			categoryVo.setId(i+1L);
			categoryVo.setName("weseal"+i);
			categoryVos.add(categoryVo);
		}
		
		indexVo.setCategoryVos(categoryVos);
		indexVo.setBannerVoList(bannerVoList);
		result.setData(indexVo);
		return result;
		
	}


	@RequestMapping(value = "/logout")
	public String logout() {
		session.removeAttribute(CommonUtils.CURRENT_MASTER_ID);
		session.removeAttribute(CommonUtils.CURRENT_MASTER);
		session.removeAttribute(CommonUtils.CURRENT_ROLE);
		removeCookie(CommonUtils.COOKIE_TICKET);
		return "login";
	}

}
